package com.example.wechat114.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.wechat114.commons.HttpClientUtil2;
import com.example.wechat114.entity.HurlJson;


import com.example.wechat114.entity.Kform;
import com.example.wechat114.entity.Registered;
import com.example.wechat114.service.HujService;
import com.example.wechat114.service.impl.HujServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;

@RestController
@RequestMapping("text")
public class TextController {
    @Autowired
    private HujService hujService;
    //北京医院
    public static String URL1 = "http://bearknight.nat300.top/wechat/hospital/getKformAll";
    //张文轩组医院
    public static String URL2 = "http://xiaoxuan.nat300.top/wechat114/hospitalSelectList";

    public static JSONObject getHX(){
        JSONObject jsonObject = HttpClientUtil2.doGet(URL1);
        return jsonObject;
    }
    @PostMapping("show")
    public String show(JSONObject jsonObject){
        if (jsonObject!=null){
            System.err.println(jsonObject.get("data").toString());
        }
        return jsonObject.get("data").toString();
    }
    @PostMapping("jiekou")
    public String jiekou(){
        show(getHX());
        return show(getHX());

    }

    @PostMapping("add")
    public String add(JSONObject jsonObject){
        show(jsonObject);
        HurlJson hurlJson = new HurlJson();
        hurlJson.sethId(1);
        hurlJson.sethUrl("http://k7k7k.nat300.top/wechat114/doctor/selectAllDoctor");
        hurlJson.sethName("北京医院");
        if (jsonObject!=null){
            Kform data = JSON.parseObject(jsonObject.get("data").toString(), Kform.class);
            System.out.println(data.toString());
//            hurlJson.sethJson(jsonObject.get("data").toString());
//            hujService = new HujServiceImpl();
//            hujService.add(hurlJson);
        }

        return jsonObject.get("data").toString();
    }
    public static void main(String[] args) {
        TextController text = new TextController();
        text.add(TextController.getHX());
    }
}
